<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Hello World!</title>

</head>

<body>
  <h1>💖 Hello World!</h1>
  <p>Welcome to your Electron application.</p>
  <button onclick="sendMessageToMain()">sendMessageToMain</button>
  <button onclick="readCard()">readCardWebPackage打包的不能在渲染进程调用</button>
  <button onclick="readCard2()">readCardMessage</button>
</body>

<script>
  //const path = require('path');
  //console.log(path);
    const {
      ipcRenderer
    } = require('electron');

    const nxmi = require('nxmi');

    console.log('xxx',nxmi.hello())


  function readCard2() {
    ipcRenderer.send('readCard', {
    name: 'name',
    sex: 'sex'
    });
  }
  function sendMessageToMain() {
    ipcRenderer.send('msg-a', {
      name: 'name',
      sex: 'sex'
    });
  }

  ipcRenderer.on('msg-b', (event, args) => {
    console.log('ipcRenderer接收到了msg-b的消息', args);
  })

 

  function readCard() {

    console.log('xxx');
    const data = {
      yljgdm: '00000002',
      ip: '127.0.0.1',
      biztype: 'J2',
      data: `
      <?xml version="1.0" encoding="GBK"?><DATA>

        <HEAD>
          <VER>01.01</VER>
          <APP>J2</APP>
          <WorkDate>20181116</WorkDate>
          <Reserve></Reserve>
          <ErrCode></ErrCode>
          <ErrDetail></ErrDetail>
        </HEAD>
        <MSG>

          <HEAD>
            <YLJGDM>00000002</YLJGDM>
            <JYRQ>20181116000000</JYRQ>
            <MZZYBZ>0</MZZYBZ>
            <ZXBXBZ>0</ZXBXBZ>
            <ZHCXBZ>1</ZHCXBZ>
            <DKXXBZ>1</DKXXBZ>
            <PWD>1</PWD>
          </HEAD>
        </MSG>
      </DATA>`
    }

    const params = {
      'functionname': 'bizbuss',
      'params': {
        'hid': data.yljgdm,
        'biztype': data.biztype,
        'ip': data.ip,
        'indata': data.data
      }
    }

    ipcRenderer.send('readCard', {
      name: 'name',
      sex: 'sex'
    });
  }
</script>

</html>